#!/usr/bin/env python
# -*- coding:utf-8 -*-


from jujub import Jujube, Consumer

def DEBUG(format, *args) : print format % args

#######################################################################


class EchoConsumer(Consumer)  :
    '''Echo Consumer'''
    def feed(self, packet, channel_from, dispatcher) :
        record = packet.body
        packet.respid = packet.packid
        packet.packid = 0
        DEBUG('COMSUMER echo: %s', record)
        self.response(packet, channel_from)
        return True
        # feed()
    # class EchoConsumer

HOST = "127.0.0.1"
PORT = 54344

def main():
    s = Jujube()
    s.listen(PORT)

    consumer = EchoConsumer()
    s.registerConsumer('ECHO', consumer)
    s.run()
    # main()

if __name__ == '__main__' :
    main()
    import sys
    sys.exit(0)
